package me.zk.practice1.hw;

import java.util.Scanner;

/**
 * @author zhangkai
 * @date 2023/7/25 16:31
 */
public class S3 {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        String s = in.nextLine();
        char[] chars = s.toCharArray();
        int sum = 0;
        for (int i = chars.length-1,j=0; i > 1; i--,j++) {
            int res = 0;

            char c = chars[i];
            if(c=='0'||c=='1'||c=='2'||c=='3'||c=='4'||c=='5'||c=='6'||c=='7'||c=='8'||c=='9'){
                res+=c-'0';
            }else{
                res+=c-'A'+10;
            }
            for (int h = 0; h < j; h++) {
                res*=16;
            }
            sum+=res;

        }

        System.out.println(sum);
    }

}
